import DictInstance from "./dictImpl/DictAsyncImpl"
//异步字典
class DictAsync {
	constructor(dict) {
		this.dict = dict;
	}

	async init(Vue, names) {
		const ps = [];
		names.forEach((name) => {
			//动态添加对象的属性
			Vue.set(this.dict, name, []);
			//异步获取字典数据
			ps.push(
				get(name).then((data) => {
					this.dict[name] = Object.freeze(data.content);
				})
			);
		});
		await Promise.all(ps);
	}
}



const install = function (Vue) {

	Vue.mixin({
		computed() {

		},
		created() {
			if (this.$options.dicts instanceof Array && this.$options.dicts.length > 0) {
				new DictInstance(this.dict/*Vue中data中的dict*/).init(Vue, this.$options.dicts/*Vue中的dicts*/);
			}
		},
	});
};

export default {
	install
}